﻿using GBT.SystemBusinessCore;
using GBT.ParamEntity;
using GBT.SystemEnties;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using Persistence.Core;
using QueryDataLogic.Core;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Linq;
using GBT.ManageEnties;

namespace PersistenceDataLogic.Core
{
    public class OperationMeal
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        PersistenceData pd = new PersistenceData();
        QueryData qd = new QueryData();
        BasicInfo bi = new BasicInfo();
        QueryDataLogic.Core.SystemSetting ss = new QueryDataLogic.Core.SystemSetting();

        /// <summary>
        /// 返回消息处理
        /// </summary>
        /// <param name="resultLine">保存数据库返回的受影响行数</param>
        /// <param name="state">客户端请求的 服务器处理状态 Add或Del</param>
        /// <param name="Date">报餐日期</param>
        /// <param name="UserID">用户ID</param>
        /// <param name="MealID">餐点ID</param>
        /// <param name="name">餐点名称</param>
        /// <param name="dbName">数据库名称</param>
        /// <returns></returns>
        private string ResultHandle(int resultLine, System_ReportMeals reportMeals, string hallName, DbContext<ReportMeals> dbContext)
        {
            StringBuilder sbMessage = new StringBuilder();
            //返回消息处理
            if (resultLine > 0)
            {
                if (reportMeals.state == "Add")
                {
                    if (reportMeals.name != "")
                    {
                        sbMessage.Append("[" + DateTime.Now.ToShortTimeString() + "]：" + reportMeals.date + " 的“" + reportMeals.name + "”报餐成功\n");
                    }
                }
                else if (reportMeals.state == "Del")
                {
                    if (reportMeals.name != "")
                    {
                        sbMessage.Append("[" + DateTime.Now.ToShortTimeString() + "]：" + reportMeals.date + " 的“" + reportMeals.name + "”撤餐成功\n");
                    }
                }
            }
            else
            {
                if (IsMealReport(reportMeals, dbContext))
                {
                    sbMessage.Append("[" + DateTime.Now.ToShortTimeString() + "]：" + reportMeals.date + " 的“" + reportMeals.name + "”已在“" + hallName + "”报餐\n");
                }
                //if (state == "Add")
                //{
                //    if (name != "")
                //    {
                //        sbMessage.Append("[" + DateTime.Now.ToShortTimeString() + "]：" + Date + " 的“" + name + "”已报餐\n");
                //    }
                //}
                //else if (state == "Del")
                //{
                //    if (name != "")
                //    {
                //        sbMessage.Append("[" + DateTime.Now.ToShortTimeString() + "]：" + Date + " 的“" + name + "”未报餐\n");
                //    }
                //}
            }

            return sbMessage.ToString();
        }

        /// <summary>
        /// 判断是否存在报餐信息
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="Date"></param>
        /// <param name="hallID"></param>
        /// <param name="mealID"></param>
        /// <returns></returns>
        internal bool IsMealReport(System_ReportMeals reportMeals, DbContext<ReportMeals> dbContext)
        {
            try
            {
                var mealReportList = dbContext.GetList(t => t.UserID == reportMeals.userID && t.Date == reportMeals.date && t.MealID == reportMeals.mealID);

                if (mealReportList.Count > 0)
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                Console.Write(ex);
            }
            return false;
        }

        /// <summary>
        /// 执行报餐
        /// </summary>
        /// <param name="reportMeals"></param>
        /// <param name="districtID"></param>
        /// <param name="dbName"></param>
        /// <returns></returns>
        private object ExeMeal(List<System_ReportMeals> reportMeals, int districtID, string dbName)
        {
            JObject joResult = new JObject();
            DbContext<ReportMeals> dbContext = new DbContext<ReportMeals>(dbName);
            var db = dbContext.Db;
            string message = "";
            bool isSuccess = false;
            int AllResultLing = 0;
            try
            {
                int resultLine = 0;

                //返回的消息
                StringBuilder sbMessage = new StringBuilder();
                System_ReportMeals reportMeal = reportMeals[0];

                string state = "";//客户端通知服务端是 新增或者删除
                string name = "";//餐点名称 消息提示用
                string hallName = bi.GetHallName(reportMeal.hallID, dbName);
                decimal? price = null;
                List<MealTime> mealTimes = bi.GetMealTime(dbName);
                UserStoredValue userStoredValue = bi.GetUserStoredValue(reportMeal.userID, dbName);

                List<UserXpenseTracker> userXpenseTrackers = new List<UserXpenseTracker>();

                db.BeginTran();
                foreach (System_ReportMeals _ReportMeals in reportMeals)
                {
                    resultLine = 0;

                    ReportMeals reportMealsNew = new ReportMeals();
                    reportMealsNew.UserID = _ReportMeals.userID;
                    reportMealsNew.HallId = _ReportMeals.hallID;
                    reportMealsNew.MealID = _ReportMeals.mealID;
                    reportMealsNew.Date = _ReportMeals.date;
                    reportMealsNew.dayIndex = _ReportMeals.dayIndex;
                    reportMealsNew.month = _ReportMeals.month;
                    reportMealsNew.qty = _ReportMeals.qty;
                    state = _ReportMeals.state;
                    name = _ReportMeals.name;
                    price = mealTimes.Where(t => t.MealId == _ReportMeals.mealID).FirstOrDefault().Price;

                    if (IsMealReport(_ReportMeals, dbContext) && state == "Add")
                    {
                        resultLine = 0;
                        AllResultLing += resultLine;
                    }
                    else
                    {
                        UserXpenseTracker userXpenseTracker = null;
                        if (state == "Add")
                        {
                            resultLine = db.Insertable(reportMealsNew).ExecuteCommand();
                            //成功新增报餐数据，才会添加消费记录
                            if (resultLine > 0 && userStoredValue != null)
                            {
                                userXpenseTracker = new UserXpenseTracker();
                                userXpenseTracker.HallID = _ReportMeals.hallID;
                                userXpenseTracker.UserID = _ReportMeals.userID;
                                userXpenseTracker.CreationDate = DateTime.Now;
                                userXpenseTracker.Value = 0 - _ReportMeals.qty * (price == null ? 0 : (decimal)price);
                                userXpenseTracker.UserValue = userStoredValue.Value + userXpenseTracker.Value;
                                userXpenseTracker.Remark = "报餐消费";
                                userStoredValue.Value = userXpenseTracker.UserValue;
                            }
                        }
                        else if (state == "Del")
                        {
                            resultLine = db.Deleteable(reportMealsNew).Where(t => t.UserID == reportMealsNew.UserID && t.HallId == reportMealsNew.HallId && t.Date == reportMealsNew.Date).ExecuteCommand();
                            //有删除成功数据 才会添加消费记录
                            if (resultLine > 0 && userStoredValue != null)
                            {
                                userXpenseTracker = new UserXpenseTracker();
                                userXpenseTracker.HallID = _ReportMeals.hallID;
                                userXpenseTracker.UserID = _ReportMeals.userID;
                                userXpenseTracker.CreationDate = DateTime.Now;
                                userXpenseTracker.Value = _ReportMeals.qty * (price == null ? 0 : (decimal)price);
                                userXpenseTracker.UserValue = userStoredValue.Value + userXpenseTracker.Value;
                                userXpenseTracker.Remark = "取消报餐";
                                userStoredValue.Value = userXpenseTracker.UserValue;
                            }
                        }
                        if (userXpenseTracker != null)
                        {
                            userXpenseTrackers.Add(userXpenseTracker);
                        }
                        AllResultLing += resultLine;
                    }

                    //返回消息处理
                    sbMessage.Append(ResultHandle(resultLine, _ReportMeals, hallName, dbContext));
                }
                if (userStoredValue != null)
                {
                    //新增报餐消费记录
                    db.Insertable(userXpenseTrackers).ExecuteCommand();
                    //更新用户账户余额
                    db.Updateable(userStoredValue).UpdateColumns(t => new { t.Value, t.UserID }).WhereColumns(t => new { t.UserID }).ExecuteCommand();
                }
                db.CommitTran();

                if (sbMessage.ToString() != "")
                {
                    message = sbMessage.ToString();
                }
                else
                {
                    message = "[" + DateTime.Now.ToShortTimeString() + "]：撤销日期为“" + reportMeal.date + "”的所有报餐。\n";
                }
                isSuccess = true;

                Console.Write("\n数据库：" + dbName + " 区域ID：" + districtID + "用户ID：" + reportMeal.userID + "\n消息：\n" + sbMessage.ToString());
                //记录客户报餐的消息
                logger.Info("\n数据库：" + dbName + " 区域ID：" + districtID + "用户ID：" + reportMeal.userID + "\n消息：\n" + sbMessage.ToString());
            }
            catch (Exception ex)
            {
                db.RollbackTran();
                Console.Write(ex);
                message = ex.Message + "\n" + ex.StackTrace;
                isSuccess = false;
            }
            return new { data = AllResultLing, state = isSuccess, message };
        }

        /// <summary>
        /// 判断是否点过菜了
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="date"></param>
        /// <param name="districtID"></param>
        /// <param name="dbName"></param>
        /// <returns></returns>
        private bool IsUserDishes(int userID, string date, int districtID, string dbName)
        {
            JArray ja = new JArray();
            try
            {
                SqlCommand comm = new SqlCommand()
                {
                    CommandText = "select id,userID,dishesID,[date],remark,districtID,hallID from UserDishes " +
                    "where districtID = @districtID and [date] = @date and userID = @userID "
                };

                comm.Parameters.AddWithValue("@userID", userID);
                comm.Parameters.AddWithValue("@date", date);
                comm.Parameters.AddWithValue("@districtID", districtID);

                ja = qd.GetData(comm, dbName);

                if (ja.Count > 0)
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                Console.Write(ex);
            }
            return false;
        }

        /// <summary>
        /// 新增或删除报餐
        /// </summary>
        /// <returns></returns>
        public object AddMeal(JObject joParam)
        {
            object result = null;
            string message = "";
            bool isSuccess = false;
            int data = 0;
            try
            {
                List<System_ReportMeals> reportMeals = new List<System_ReportMeals>();
                reportMeals = JsonConvert.DeserializeObject<List<System_ReportMeals>>(joParam["meal"].ToString());
                //logger.Info(jaParam);

                //因为区域ID在JSON数组中的每项都相同所以提取第一项即可，来获取数据库名称 提高性能
                System_ReportMeals report = reportMeals[0];
                int districtID = report.districtID;
                int userID = report.userID;
                string date = report.date.ToString();
                string dbName = bi.GetDBName(districtID);
                Versions versions = bi.GetVersions(districtID);
                //判断系统版本是否有报餐功能， 系统版本号为 5-旗舰无报餐版 则提示无报餐功能
                if (versions.Number != "5")
                {
                    JObject joSetting = ss.GetSystemSetting(districtID);
                    bool ConstraintDishes = (bool)joSetting["ConstraintDishes"];

                    //强制点菜时，控制报餐时必须先点菜
                    if (ConstraintDishes)
                    {
                        //判断用户是否点过菜了，点过菜则执行报餐，未点过菜则提示先点菜
                        if (IsUserDishes(userID, date, districtID, dbName))
                        {
                            result = ExeMeal(reportMeals, districtID, dbName);
                        }
                        else
                        {
                            message = "[" + DateTime.Now.ToShortTimeString() + "]：日期:“" + date + "”未点菜，请先点菜。\n";
                            data = 0;
                            isSuccess = false;
                            result = new { data, start = isSuccess, message };
                        }
                    }
                    else
                    {
                        result = ExeMeal(reportMeals, districtID, dbName);
                    }
                }
                else
                {
                    data = 0;
                    message = "改系统版本无报餐功能";
                    isSuccess = false;
                    result = new { data, start = isSuccess, message };
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                data = 0;
                message = ex.Message + "\n" + ex.StackTrace;
                isSuccess = false;
                result = new { data, start = isSuccess, message };
            }
            return result;
        }

        /// <summary>
        /// 修改报餐
        /// </summary>
        /// <param name="reportMeal"></param>
        /// <returns></returns>
        public int ModifyMeal(ReportMeals reportMeal)
        {
            var dbName = bi.GetDBName(reportMeal.DistrictID);
            DbContext<ReportMeals> dbContext = new DbContext<ReportMeals>(dbName);
            var db = dbContext.Db;
            int result = 0;
            try
            {
                db.BeginTran();
                ReportMeals reportMeals = new ReportMeals();
                reportMeals.ID = reportMeal.ID;
                reportMeals.HallId = reportMeal.HallId;
                result = db.Updateable(reportMeals).UpdateColumns(t => new { t.HallId, t.ID, t.DistrictID })
                    .WhereColumns(t => new { t.ID, t.DistrictID }).ExecuteCommand();
                db.CommitTran();
            }
            catch (Exception ex)
            {
                db.RollbackTran();
                throw ex;
            }
            return result;
        }

        /// <summary>
        /// 新增 家属报餐
        /// </summary>
        /// <returns></returns>
        public JObject AddFamilyIncrementalMeal(JObject joParam)
        {
            JObject joResult = new JObject();

            try
            {
                int resultLine = 0;

                int UserID = (int)joParam["userID"];
                int HallID = (int)joParam["hallID"];
                string Date = (string)joParam["date"];
                int MealID = (int)joParam["mealID"];
                int qty = (int)joParam["qty"];
                string state = (string)joParam["state"];
                int type = (int)joParam["type"];
                int districtID = (int)joParam["districtID"];
                string dbName = bi.GetDBName(districtID);

                SqlCommand comm = new SqlCommand();
                if (state == "add")
                {
                    comm.CommandText = "INSERT INTO IncrementalMeal(type,UserID,HallID,Date,MealID,qty,districtID,creatorId) VALUES(@type,@UserID,@HallID,@Date,@MealID,@qty,@districtID,@UserID)";
                }
                else if (state == "modify")
                {
                    comm.CommandText = "UPDATE IncrementalMeal SET HallID = @HallID,MealID = @MealID, Date = @Date,qty = @qty WHERE type = @type AND UserID = @UserID AND HallID = @HallID AND MealID = @MealID AND Date = @Date ";
                }
                else if (state == "del")
                {
                    comm.CommandText = "DELETE FROM IncrementalMeal WHERE type = @type AND UserID = @UserID AND HallID = @HallID AND MealID = @MealID AND Date = @Date ";
                }

                comm.Parameters.AddWithValue("@type", type);
                comm.Parameters.AddWithValue("@UserID", UserID);
                comm.Parameters.AddWithValue("@HallID", HallID);
                comm.Parameters.AddWithValue("@Date", Date);
                comm.Parameters.AddWithValue("@MealID", MealID);
                comm.Parameters.AddWithValue("@qty", qty);
                comm.Parameters.AddWithValue("@districtID", districtID);

                resultLine = pd.ExeSqlCode(comm, dbName);

                if (state == "add" && resultLine > 0)
                {
                    joResult["message"] = "添加家属报餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "add" && resultLine <= 0)
                {
                    joResult["message"] = "添加家属报餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
                else if (state == "modify" && resultLine > 0)
                {
                    joResult["message"] = "修改家属报餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "modify" && resultLine <= 0)
                {
                    joResult["message"] = "修改家属报餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
                else if (state == "del" && resultLine > 0)
                {
                    joResult["message"] = "删除家属报餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "del" && resultLine <= 0)
                {
                    joResult["message"] = "删除家属报餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                joResult["data"] = 0;
                joResult["message"] = ex.Message + "\n" + ex.StackTrace;
                joResult["state"] = false;
            }
            return joResult;
        }

        /// <summary>
        /// 新增 临时报餐
        /// </summary>
        /// <returns></returns>
        public JObject AddInterimIncrementalMeal(JObject joParam)
        {
            JObject joResult = new JObject();

            try
            {
                int resultLine = 0;

                int UserID = (int)joParam["userID"];
                int HallID = (int)joParam["hallID"];
                string Date = (string)joParam["date"];
                int MealID = (int)joParam["mealID"];
                int qty = (int)joParam["qty"];
                string state = (string)joParam["state"];
                int type = (int)joParam["type"];
                int districtID = (int)joParam["districtID"];
                string Remark = (string)joParam["remark"];
                //string CreatorId = (string)joParam["creatorId"];
                string dbName = bi.GetDBName(districtID);

                SqlCommand comm = new SqlCommand();
                if (state == "add")
                {
                    comm.CommandText = "INSERT INTO IncrementalMeal(type,UserID,HallID,Date,MealID,qty,districtID,Remark,creatorId) VALUES(@type,@UserID,@HallID,@Date,@MealID,@qty,@districtID,@Remark,@UserID)";
                }
                else if (state == "modify")
                {
                    comm.CommandText = "UPDATE IncrementalMeal SET HallID = @HallID,MealID = @MealID, Date = @Date,qty = @qty,Remark=@Remark WHERE type = @type AND UserID = @UserID AND HallID = @HallID AND MealID = @MealID AND Date = @Date ";
                }
                else if (state == "del")
                {
                    comm.CommandText = "DELETE FROM IncrementalMeal WHERE type = @type AND UserID = @UserID AND HallID = @HallID AND MealID = @MealID AND Date = @Date ";
                }

                comm.Parameters.AddWithValue("@type", type);
                comm.Parameters.AddWithValue("@UserID", UserID);
                comm.Parameters.AddWithValue("@HallID", HallID);
                comm.Parameters.AddWithValue("@Date", Date);
                comm.Parameters.AddWithValue("@MealID", MealID);
                comm.Parameters.AddWithValue("@qty", qty);
                comm.Parameters.AddWithValue("@districtID", districtID);
                comm.Parameters.AddWithValue("@Remark", Remark);
                //comm.Parameters.AddWithValue("@creatorId", CreatorId);

                resultLine = pd.ExeSqlCode(comm, dbName);

                if (state == "add" && resultLine > 0)
                {
                    joResult["message"] = "添加临时报餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "add" && resultLine <= 0)
                {
                    joResult["message"] = "添加临时报餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
                else if (state == "modify" && resultLine > 0)
                {
                    joResult["message"] = "修改临时报餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "modify" && resultLine <= 0)
                {
                    joResult["message"] = "修改临时报餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
                else if (state == "del" && resultLine > 0)
                {
                    joResult["message"] = "删除临时报餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "del" && resultLine <= 0)
                {
                    joResult["message"] = "删除临时报餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }

            }
            catch (Exception ex)
            {
                Console.Write(ex);
                joResult["data"] = 0;
                joResult["message"] = ex.Message + "\n" + ex.StackTrace;
                joResult["state"] = false;
            }

            return joResult;
        }

        /// <summary>
        /// 操作 加班餐
        /// </summary>
        /// <returns></returns>
        public JObject AddWorkOvertimeMeal(JObject joParam)
        {
            JObject joResult = new JObject();

            try
            {
                int resultLine = 0;

                int UserID = (int)joParam["userID"];
                int HallID = (int)joParam["hallID"];
                string Date = (string)joParam["date"];
                int MealID = (int)joParam["mealID"];//固定晚餐 客户端传入
                int qty = (int)joParam["qty"];
                string state = (string)joParam["state"];
                int districtID = (int)joParam["districtID"];
                string Remark = (string)joParam["remark"];
                string dbName = bi.GetDBName(districtID);

                SqlCommand comm = new SqlCommand();
                if (state == "add")
                {
                    comm.CommandText = "INSERT INTO IncrementalMeal(type,UserID,HallID,Date,MealID,qty,districtID,Remark, isAudit, creatorId) VALUES(3,@UserID,@HallID,@Date,@MealID,@qty,@districtID,@Remark, 0, @UserID)";
                }
                else if (state == "modify")
                {
                    //客户端判断已审核无法修改 移除对应的按钮
                    comm.CommandText = "UPDATE IncrementalMeal SET HallID = @HallID,MealID = @MealID, Date = @Date,qty = @qty,Remark=@Remark WHERE type = 3 AND UserID = @UserID AND HallID = @HallID AND MealID = @MealID AND Date = @Date ";
                }
                else if (state == "del")
                {
                    //客户端判断已审核无法删除 移除对应的按钮
                    comm.CommandText = "DELETE FROM IncrementalMeal WHERE type = 3 AND UserID = @UserID AND HallID = @HallID AND MealID = @MealID AND Date = @Date ";
                }

                comm.Parameters.AddWithValue("@UserID", UserID);
                comm.Parameters.AddWithValue("@HallID", HallID);
                comm.Parameters.AddWithValue("@Date", Date);
                comm.Parameters.AddWithValue("@MealID", MealID);
                comm.Parameters.AddWithValue("@qty", qty);
                comm.Parameters.AddWithValue("@districtID", districtID);
                comm.Parameters.AddWithValue("@Remark", Remark);

                resultLine = pd.ExeSqlCode(comm, dbName);

                if (state == "add" && resultLine > 0)
                {
                    joResult["message"] = "添加加班餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "add" && resultLine <= 0)
                {
                    joResult["message"] = "添加加班餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
                else if (state == "modify" && resultLine > 0)
                {
                    joResult["message"] = "修改加班餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "modify" && resultLine <= 0)
                {
                    joResult["message"] = "修改加班餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
                else if (state == "del" && resultLine > 0)
                {
                    joResult["message"] = "删除加班餐 " + Date + " 成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else if (state == "del" && resultLine <= 0)
                {
                    joResult["message"] = "删除加班餐 " + Date + " 失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }

            }
            catch (Exception ex)
            {
                Console.Write(ex);
                joResult["data"] = 0;
                joResult["message"] = ex.Message + "\n" + ex.StackTrace;
                joResult["state"] = false;
            }

            return joResult;
        }

        /// <summary>
        /// 审核/取消审核 加班餐
        /// </summary>
        /// <param name="districtID"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public JObject AuditMeal(JObject joParam)
        {
            JObject joResult = new JObject();
            try
            {
                int districtID = (int)joParam["districtId"];
                int id = (int)joParam["id"];
                bool isAudit = (bool)joParam["isAudit"];
                int resultLine = 0;
                string dbName = bi.GetDBName(districtID);
                SqlCommand scomm = new SqlCommand()
                {
                    CommandText = "UPDATE IncrementalMeal SET isAudit = @isAudit WHERE ID = @id and Type = 3"
                };

                scomm.Parameters.AddWithValue("@id", id);
                scomm.Parameters.AddWithValue("@isAudit", isAudit);
                resultLine = pd.ExeSqlCode(scomm, dbName);

                if (resultLine > 0)
                {
                    joResult["message"] = "审批成功";
                    joResult["data"] = resultLine;
                    joResult["state"] = true;
                }
                else
                {
                    joResult["message"] = "审批失败";
                    joResult["data"] = resultLine;
                    joResult["state"] = false;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                joResult["data"] = 0;
                joResult["message"] = ex.Message + "\n" + ex.StackTrace;
                joResult["state"] = false;
            }
            return joResult;
        }
    }
}
